//
//  LSCompetitionActionCell.m
//  LookScore
//
//  Created by wr on 2017/12/9.
//  Copyright © 2017年 ChongQingXunTiCompany. All rights reserved.
//


#define scoreWidth ((LSScreenWidth-30)*0.3)/3
#import "LSCompetitionModel.h"

#import "LSCompetitionActionCell.h"
#import "LSMatchScheduleModel.h"
#import "LSTimerManeger.h"

#import "LSCompetitiomView.h"
#import "LSLayout.h"
@interface LSCompetitionActionCell()

@property(strong,nonatomic)UILabel *cupTypeLabel;

@property(strong,nonatomic)UILabel *timerLabel;
@property (nonatomic, strong) UILabel *stateLabel;
@property (nonatomic, strong) UIImageView * jiaoqiuImg;
@property (nonatomic, strong) UIButton * attentionBtn;

@property (nonatomic, strong) LSCompetitiomView * left1View;
@property (nonatomic, strong) LSCompetitiomView * left2View;
@property (nonatomic, strong) LSCompetitiomView * right1View;
@property (nonatomic, strong) LSCompetitiomView * right2View;
@property (nonatomic, strong) UILabel * halfScoreLabel;
@property (nonatomic, strong) UILabel * jiaoqiuScoreLabel;
@property (nonatomic, strong) UILabel * secondsLabel;
@property (nonatomic, strong) LSCompetitionSubView * midView;

@end

@implementation LSCompetitionActionCell{
    
    CGFloat angle;
    LSCompetitiomTopSubView * _topView;
    LSCompetitiomSubBottomView * _bottomView;
}

+(LSCompetitionActionCell *)CompetitionActionTableviewCellByTableView:(UITableView *)tableView{
    LSCompetitionActionCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cellId"];
    if (!cell) {
        cell = [[LSCompetitionActionCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellId"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //        [self addContentView];
        [self createView];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(countDownNotification) name:LSCountDownNotification object:nil];
    }
    
    return self;
}

- (LSCompetitionSubView *)midView{
    if (!_midView) {
        _midView = [[LSCompetitionSubView alloc] init];
        _midView.backgroundColor = LSTitleWhiteColor;
    }
    return _midView;
}

- (void)createView{
    
    _topView = [[LSCompetitiomTopSubView alloc] init];
    [self.contentView addSubview:_topView];
    [self.contentView addSubview: self.midView];
    _bottomView = [[LSCompetitiomSubBottomView alloc] init];
    [self.contentView addSubview:_bottomView];
    
}


- (void)setLayout:(LSLayout *)layout{
    
    _layout = layout;
    CGFloat top = 0;
    _topView.height = layout.firstH;
    _topView.cupTypeLabel.textLayout = layout.cupLayout;
    _topView.cupTypeLabel.height = layout.cupLayout.textBoundingSize.height;
    _topView.cupTypeLabel.width  = layout.cupLayout.textBoundingSize.width;
    //    _topView.cupTypeLabel.size = layout.cupLayout.textBoundingSize;
    _topView.cupTypeLabel.centerY = _topView.centerY;
    _topView.cupTypeLabel.textAlignment = NSTextAlignmentCenter;
    KWeakSelf(self);
    _topView.block = ^(UIButton *sender) {
        sender.selected=!sender.selected;
        if (weakself.block) {
            weakself.block(sender);
        }
    };
    _topView.attendBtn.selected = layout.model.isSelected;
    _topView.timeLabel.textLayout = layout.timeLayout;
    _topView.timeLabel.height = layout.timeLayout.textBoundingSize.height;
    _topView.timeLabel.centerY = _topView.centerY;
    
    _topView.statelLabel.textLayout = layout.stateLayout;
    _topView.statelLabel.height = layout.stateLayout.textBoundingSize.height;
    //    _topView.statelLabel.width = layout.stateLayout.textBoundingSize.width;
    _topView.statelLabel.centerY = _topView.centerY;
    //    _topView.statelLabel.centerX = _topView.centerX;
    _topView.statelLabel.textAlignment = NSTextAlignmentCenter;
    
    _topView.runBallImageView.hidden = layout.runBallIsHidden;
    _topView.secondLabel.hidden = layout.secondLabelISHidden;
    _topView.top = top;
    _topView.left = 0;
    top = layout.firstH;
    
    self.midView.height = layout.secondH;
    //比分
    self.midView.scoreLabel.textLayout = layout.scoreLayout;
    self.midView.scoreLabel.centerY = self.midView.height/2;
    //主队名
    self.midView.hostNameLabel.textLayout = layout.hostNameLayout;
    self.midView.hostNameLabel.centerY = self.midView.height/2;
    //主队排名
    self.midView.hostRankLabel.textLayout = layout.hostRankLayout;
    self.midView.hostRankLabel.size = layout.hostRankLayout.textBoundingSize;
    self.midView.hostRankLabel.centerY = self.midView.height/2;
    self.midView.hostRankLabel.hidden = layout.homeRankHidden;
    //客队名
    self.midView.guestNameLabel.textLayout = layout.guestNameLayout;
    self.midView.guestNameLabel.centerY = self.midView.height/2;
    //客队排名
    self.midView.guestRankLabel.textLayout = layout.guestRankLayout;
    self.midView.guestRankLabel.size = layout.guestRankLayout.textBoundingSize;
    self.midView.guestRankLabel.centerY = self.midView.height/2;
    self.midView.guestRankLabel.hidden = layout.guestRankHidden;
    
    self.midView.top = top;
    top += layout.secondH;
    
    _bottomView.top = top;
    _bottomView.height = layout.bottomH;
    _bottomView.banLabel.textLayout = layout.banLayout;
    _bottomView.banLabel.centerY = _bottomView.height/2;
    
    _bottomView.homeRedLabel.textLayout = layout.homeRedLayout;
    _bottomView.homeRedLabel.centerY = _bottomView.height/2;
    
    _bottomView.homeYellowLabel.textLayout = layout.homeYellowLayout;
    _bottomView.homeYellowLabel.centerY = _bottomView.height/2;
    
    _bottomView.jiaoLabel.textLayout = layout.jiaoLayout;
    _bottomView.jiaoLabel.centerY = _bottomView.height/2;
    _bottomView.jiaoLabel.hidden = !layout.hasJiaoqiu;
    
    _bottomView.guestRedLabel.textLayout = layout.guestRedLayout;
    _bottomView.guestRedLabel.centerY = _bottomView.height/2;
    
    _bottomView.guestYellowLabel.textLayout = layout.guestYellowLayout;
    _bottomView.guestYellowLabel.centerY = _bottomView.height/2;
    self.contentView.height = layout.firstH + layout.secondH + layout.bottomH;
    self.height = layout.firstH + layout.secondH + layout.bottomH;
    
    [self countDownNotification];
}

- (void)countDownNotification{
    
    if ( self.layout.model.MatchState == 1 || self.layout.model.MatchState == 3) {
        //        MyLog(@"%ld",kLSTimerManeger.timeInterval);
        if (kLSTimerManeger.timeInterval % 2 == 0) {
            _topView.secondLabel.hidden = YES;
        }else{
            _topView.secondLabel.hidden = NO;
        }
    }else{
        _topView.secondLabel.hidden = YES;
    }
    
    if (self.layout.model.HasZouDi) {
        
        if (self.layout.model.MatchState==1 || self.layout.model.MatchState == 3 || self.layout.model.MatchState == 2 ||self.layout.model.MatchState == 4) {
            
            [self startAnimation];
        }else{
            [self stopLoopAnimation];
        }
    }else{
        
        [self stopLoopAnimation];
    }
    
}

//分割时间字符串
- (NSString *)getTimeStrWithStr:(NSString *)timeStr{
    
    NSString * timeStr1 = [timeStr componentsSeparatedByString:@"T"].lastObject;
    NSArray * array1 = [timeStr1 componentsSeparatedByString:@":"];
    NSMutableArray * array2 = [NSMutableArray arrayWithArray:array1];
    [array2 removeLastObject];
    [array2 removeLastObject];
    NSString * str = [array2 componentsJoinedByString:@":"];
    str = [str componentsSeparatedByString:@"+"].firstObject;
    return str;
}

- (void)setType:(NSInteger)type{
    
    _type = type;
    if (type == 2) {
        _topView.attendBtn.hidden = YES;
    }else{
        _topView.attendBtn.hidden = NO;
    }
    
}
//图文混排
- (NSAttributedString *)graphicMixedWithImage:(UIImage *)image WithText:(NSString *)text{
    
    NSTextAttachment * yellowAttach = [[NSTextAttachment alloc] init];
    yellowAttach.bounds = CGRectMake(0, -4, 15, 17);
    yellowAttach.image = image;
    NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:yellowAttach];
    NSMutableAttributedString * attriButStr = [[NSMutableAttributedString alloc] initWithString:text];
    [attriButStr addAttributes:@{NSForegroundColorAttributeName:LSTitleGrayColor2,NSFontAttributeName:LSFontSize13,} range:NSMakeRange(0, text.length)];
    [attriButStr insertAttributedString:string atIndex:0];
    return attriButStr;
}


- (void)setMyIndexPath:(NSIndexPath *)myIndexPath{
    _myIndexPath = myIndexPath;
    if (myIndexPath.section == 0) {
        if (self.model.HasCorner) {
            self.jiaoqiuScoreLabel.hidden = NO;
            
        }else{
            self.jiaoqiuScoreLabel.hidden = YES;
            
        }
        //        [self startAnimation];
        [self countDownNotification];
    }else if (myIndexPath.section == 1){
        //未开始
        
        self.stateLabel.textColor = RGB(119,119,119);
        self.halfScoreLabel.hidden = YES;
        self.jiaoqiuScoreLabel.hidden = YES;
        //        [self stopLoopAnimation];
    }else{
        
        //        [self stopLoopAnimation];
    }
}

- (void)setModel:(LSCompetitionModel *)model{
    
    _model = model;
    self.midView.model = model;
    self.cupTypeLabel.text = model.LeagueName_CN;
    self.cupTypeLabel.textColor = [CommonClass colorWithHexString:model.LeagueColor];
    self.halfScoreLabel.text = [NSString stringWithFormat:@"半%@-%@",model.HomeTeamHalfScore,model.GuestTeamHalfScore];
    
    
    //    self.hostNameLabel.attributedText = [CommonClass htmlStrTraslateNormalStrWithHtml:model.HomeTeamName_CN Withfont:LSFontSize(15, LSScreenWidth) withColor:RGB(32,32,32)];
    //    self.guestNameLabel.attributedText = [CommonClass htmlStrTraslateNormalStrWithHtml:model.GuestTeamName_CN Withfont:LSFontSize(15, LSScreenWidth) withColor:RGB(32,32,32)];
    [self.left1View setImage:@"黄牌" withNumber:model.HomeTeamYellowCard];
    [self.left2View setImage:@"红牌" withNumber:model.HomeTeamRedCard];
    [self.right1View setImage:@"黄牌" withNumber:model.GuestTeamYellowCard];
    [self.right2View setImage:@"红牌" withNumber: model.GuestTeamRedCard];
    
    self.timerLabel.text = [self getTimeStrWithStr:model.MatchDateTime];
    switch (model.MatchState) {
        case -1:{
            //结束
            self.stateLabel.text = @"完";
            self.stateLabel.textColor = RGB(119,119,119);
            self.halfScoreLabel.hidden = NO;
            
            if (model.HasCorner){
                self.jiaoqiuScoreLabel.hidden = NO;
                self.jiaoqiuScoreLabel.text = [NSString stringWithFormat:@"角%@-%@",model.HomeTeamCorner,model.GuestTeamCorner];
            }else{
                self.jiaoqiuScoreLabel.hidden = YES;
            }
            
            
        }
            break;
        case 0:{
            self.stateLabel.text = @"未";
            //            //未开始
            //            self.stateLabel.text = @"未";
            //            self.scoreLabel.textColor = RGB(180,180,180);
            //            self.scoreLabel.text = @"VS";
            //            self.stateLabel.textColor = RGB(119,119,119);
            //            self.hostNameLabel.textColor = RGB(119,119,119);
            //            self.guestNameLabel.textColor = RGB(119,119,119);
            //            //            NSRunLoop * loop = [[NSRunLoop alloc] init];
            //
            //            self.timerLabel.text = [self getTimeStrWithStr:model.MatchDateTime];
            //            self.halfScoreLabel.hidden = YES;
            //            self.jiaoqiuScoreLabel.hidden = YES;
        }
            break;
            
        case 1:{
            //上半场
            self.stateLabel.text = [NSString stringWithFormat:@"%@",model.MatchRunTime];
            self.stateLabel.textColor = RGB(242,94,89);
            self.halfScoreLabel.hidden = NO;
            
            //            if (model.HasCorner) {
            //                self.jiaoqiuScoreLabel.hidden = NO;
            //
            //            }else{
            //                self.jiaoqiuScoreLabel.hidden = YES;
            //
            //            }
            self.jiaoqiuScoreLabel.text = [NSString stringWithFormat:@"角%@-%@",model.HomeTeamCorner,model.GuestTeamCorner];
            // 手动调用通知的回调
            //            [self countDownNotification];
        }
            break;
        case 3:{
            //下半场
            self.stateLabel.text = [NSString stringWithFormat:@"%@",model.MatchRunTime];
            self.stateLabel.textColor = RGB(242,94,89);
            self.halfScoreLabel.hidden = NO;
            if (model.HasCorner){
                self.jiaoqiuScoreLabel.hidden = NO;
                self.jiaoqiuScoreLabel.text = [NSString stringWithFormat:@"角%@-%@",model.HomeTeamCorner,model.GuestTeamCorner];
            }else{
                self.jiaoqiuScoreLabel.hidden = YES;
            }
            // 手动调用通知的回调
            //            [self countDownNotification];
        }
            break;
        case 4:{
            self.stateLabel.text = [NSString stringWithFormat:@"%@",model.MatchRunTime];
            self.stateLabel.textColor = RGB(242,94,89);
            self.halfScoreLabel.hidden = NO;
            if (model.HasCorner){
                self.jiaoqiuScoreLabel.hidden = NO;
                self.jiaoqiuScoreLabel.text = [NSString stringWithFormat:@"角%@-%@",model.HomeTeamCorner,model.GuestTeamCorner];
            }else{
                self.jiaoqiuScoreLabel.hidden = YES;
            }
            //            if (model.HasCorner) {
            //                self.jiaoqiuScoreLabel.hidden = NO;
            //
            //            }else{
            //                self.jiaoqiuScoreLabel.hidden = YES;
            //
            //            }
        }
            break;
        case -12:{
            self.jiaoqiuScoreLabel.hidden = YES;
            self.stateLabel.text = @"取消";
            self.halfScoreLabel.hidden = YES;
        }
            break;
        case -14:{
            self.jiaoqiuScoreLabel.hidden = YES;
            self.stateLabel.text = @"延时";
            self.halfScoreLabel.hidden = NO;
        }
            break;
        case 2:{
            self.jiaoqiuScoreLabel.hidden = YES;
            self.stateLabel.text = @"中场";
            self.halfScoreLabel.hidden = NO;
            self.jiaoqiuScoreLabel.text = [NSString stringWithFormat:@"角%@-%@",model.HomeTeamCorner,model.GuestTeamCorner];
            // 手动调用通知的回调
            //            [self countDownNotification];
        }
            break;
        case -11:{
            self.jiaoqiuScoreLabel.hidden = YES;
            self.stateLabel.text = @"待定";
            self.timerLabel.text = [self getTimeStrWithStr:model.MatchDateTime];
            self.halfScoreLabel.hidden = NO;
        }
            break;
        default:
            break;
    }
    
    if ([model.HomeTeamYellowCard isEqualToString:@"0"]) {
        self.left1View.hidden = YES;
    }else{
        
        self.left1View.hidden = NO;
    }
    if ([model.HomeTeamRedCard isEqualToString:@"0"]) {
        self.left2View.hidden = YES;
    }else{
        self.left2View.hidden = NO;
    }
    if ([model.GuestTeamYellowCard isEqualToString:@"0"]) {
        self.right1View.hidden = YES;
    }else{
        self.right1View.hidden = NO;
    }
    
    if ([model.GuestTeamRedCard isEqualToString:@"0"]) {
        self.right2View.hidden = YES;
    }else{
        self.right2View.hidden = NO;
        
    }
    
    self.jiaoqiuImg.hidden = ! model.HasZouDi;
    self.attentionBtn.selected = model.isSelected;
}



- (void)startAnimation{
    CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = [NSNumber numberWithFloat:M_PI * 2.0];
    rotationAnimation.duration = 0.5;
    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount =ULLONG_MAX;
    [_topView.runBallImageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
    
    
}
-(void)stopLoopAnimation{
    [_topView.runBallImageView.layer removeAllAnimations];
    
}


#pragma mark 🔥 attention Event
-(void)competitionAttentionEvent:(UIButton *)sender{
    sender.selected=!sender.selected;
    
    self.block(sender);
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end

#pragma mark -- LSCompetitionSubView
@implementation LSCompetitionSubView
- (YYLabel *)scoreLabel{
    if (!_scoreLabel) {
        _scoreLabel = [[YYLabel alloc] init];
        _scoreLabel.size = CGSizeMake(50, 30);
        _scoreLabel.displaysAsynchronously = YES;
        _scoreLabel.ignoreCommonProperties = YES;
        _scoreLabel.fadeOnAsynchronouslyDisplay = NO;
        _scoreLabel.fadeOnHighlight = NO;
        _scoreLabel.font = LSFontSize16;
        _scoreLabel.textVerticalAlignment = YYTextVerticalAlignmentCenter;
    }
    return _scoreLabel;
}

- (YYLabel *)hostNameLabel{
    if (!_hostNameLabel) {
        _hostNameLabel = [[YYLabel alloc] init];
        _hostNameLabel.font = LSFontSize(14,LSScreenWidth);
        _hostNameLabel.textVerticalAlignment = YYTextVerticalAlignmentCenter;
        _hostNameLabel.backgroundColor = LSTitleWhiteColor;
        _hostNameLabel.size = CGSizeMake(LSAutoVlaue(110, LSScreenWidth), 30);
        _hostNameLabel.displaysAsynchronously = YES;
        _hostNameLabel.ignoreCommonProperties = YES;
        _hostNameLabel.fadeOnAsynchronouslyDisplay = NO;
        _hostNameLabel.fadeOnHighlight = NO;
        
        
    }
    return _hostNameLabel;
}
- (YYLabel *)hostRankLabel{
    if (!_hostRankLabel) {
        _hostRankLabel =  [[YYLabel alloc] init];
        _hostRankLabel.font = LSFontSize10;
        //        _hostRankLabel.text = @"[17]";
        _hostRankLabel.textColor = RGB(93,93,93);
        _hostRankLabel.textVerticalAlignment = YYTextVerticalAlignmentCenter;
        _hostRankLabel.hidden = YES;
        _hostRankLabel.backgroundColor = LSTitleWhiteColor;
        _hostRankLabel.size = CGSizeMake(LSScareValue(40, LSScreenWidth), 30);
        _hostRankLabel.displaysAsynchronously = YES;
        _hostRankLabel.ignoreCommonProperties = YES;
        _hostRankLabel.fadeOnAsynchronouslyDisplay = NO;
        _hostRankLabel.fadeOnHighlight = NO;
    }
    return _hostRankLabel;
}
- (YYLabel *)guestNameLabel{
    if (!_guestNameLabel) {
        _guestNameLabel = [[YYLabel alloc] init];
        _guestNameLabel.font = LSFontSize(14,LSScreenWidth);
        _guestNameLabel.textVerticalAlignment = YYTextVerticalAlignmentCenter;
        _guestNameLabel.backgroundColor = LSTitleWhiteColor;
        _guestNameLabel.size = CGSizeMake(LSAutoVlaue(110, LSScreenWidth), 30);
        _guestNameLabel.displaysAsynchronously = YES;
        _guestNameLabel.ignoreCommonProperties = YES;
        _guestNameLabel.fadeOnAsynchronouslyDisplay = NO;
        _guestNameLabel.fadeOnHighlight = NO;
    }
    return _guestNameLabel;
}
- (YYLabel *)guestRankLabel{
    if (!_guestRankLabel) {
        _guestRankLabel =  [[YYLabel alloc] init];
        _guestRankLabel.font = LSFontSize10;
        _guestRankLabel.textColor = RGB(93,93,93);
        _guestRankLabel.textVerticalAlignment = YYTextVerticalAlignmentCenter;
        _guestRankLabel.hidden = YES;
        _guestRankLabel.backgroundColor = LSTitleWhiteColor;
        _guestRankLabel.size = CGSizeMake(LSScareValue(40, LSScreenWidth), 30);
        _guestRankLabel.displaysAsynchronously = YES;
        _guestRankLabel.ignoreCommonProperties = YES;
        _guestRankLabel.fadeOnAsynchronouslyDisplay = NO;
        _guestRankLabel.fadeOnHighlight = NO;
    }
    return _guestRankLabel;
}

- (instancetype)initWithFrame:(CGRect)frame{
    if (frame.size.width == 0 && frame.size.height == 0) {
        frame.size.width = LSScreenWidth;
        frame.size.height = 30;
    }
    if (self = [super initWithFrame:frame]) {
        [self addContentView];
    }
    return self;
}


- (void) addContentView{
    //比分
    [self addSubview:self.scoreLabel];
    self.scoreLabel.centerX = self.centerX;
    self.scoreLabel.centerY = self.centerY;
    //主队名字
    [self addSubview:self.hostNameLabel];
    self.hostNameLabel.right = self.scoreLabel.origin.x - 5;
    self.hostNameLabel.centerY = self.scoreLabel.centerY;
    //主队排名
    [self addSubview:self.hostRankLabel];
    self.hostRankLabel.centerY = self.scoreLabel.centerY;
    self.hostRankLabel.right = self.hostNameLabel.origin.x-3;
    //客队名
    [self addSubview:self.guestNameLabel];
    self.guestNameLabel.left = self.scoreLabel.right + 5;
    self.guestNameLabel.centerY = self.scoreLabel.centerY;
    //客队排名
    [self addSubview:self.guestRankLabel];
    
    self.guestRankLabel.left = self.guestNameLabel.right + 3;
    self.guestRankLabel.centerY = self.guestNameLabel.centerY;
    
}
@end;

#pragma mark -- LSCompititonTopSubview
@interface LSCompetitiomTopSubView()
@end

@implementation LSCompetitiomTopSubView

- (instancetype)initWithFrame:(CGRect)frame{
    if (frame.size.width == 0 && frame.size.height == 0) {
        frame.size.width = LSScreenWidth;
        frame.size.height = 30;
    }
    if (self = [super initWithFrame:frame]) {
        //联赛名
        _cupTypeLabel = [YYLabel new];
        _cupTypeLabel.displaysAsynchronously = YES;
        _cupTypeLabel.ignoreCommonProperties = YES;
        _cupTypeLabel.fadeOnHighlight = NO;
        _cupTypeLabel.fadeOnAsynchronouslyDisplay = NO;
        _cupTypeLabel.left = 10;
        _cupTypeLabel.centerY = self.height/2;
        _cupTypeLabel.size = CGSizeMake(50, 30);
        [self addSubview:_cupTypeLabel];
        
        //开赛时间
        _timeLabel = [YYLabel new];
        _timeLabel.textAlignment = NSTextAlignmentCenter;
        _timeLabel.displaysAsynchronously = YES;
        _timeLabel.ignoreCommonProperties = YES;
        _timeLabel.fadeOnHighlight = NO;
        _timeLabel.fadeOnAsynchronouslyDisplay = NO;
        _timeLabel.size = CGSizeMake(50, 30);
        _timeLabel.left = _cupTypeLabel.origin.x +_cupTypeLabel.width+5;
        _cupTypeLabel.centerY = self.height/2;
        [self addSubview:_timeLabel];
        //状态
        _statelLabel = [YYLabel new];
        _statelLabel.textAlignment = NSTextAlignmentCenter;
        _statelLabel.displaysAsynchronously = YES;
        _statelLabel.ignoreCommonProperties = YES;
        _statelLabel.fadeOnAsynchronouslyDisplay = NO;
        _statelLabel.fadeOnHighlight = YES;
        _statelLabel.size = CGSizeMake(25, 30);
        _statelLabel.centerY = self.height/2;
        _statelLabel.centerX = self.width/2;
        [self addSubview:_statelLabel];
        //秒针
        _secondLabel = [YYLabel new];
        _secondLabel.text = @"'";
        _secondLabel.textColor = RGB(242,94,89);
        _secondLabel.displaysAsynchronously = YES;
        _secondLabel.ignoreCommonProperties = YES;
        _secondLabel.fadeOnAsynchronouslyDisplay = NO;
        _secondLabel.fadeOnHighlight = NO;
        _secondLabel.size = CGSizeMake(3, 20);
        _secondLabel.left = _statelLabel.origin.x+_statelLabel.width;
        _secondLabel.top = 5;
        [self addSubview:_secondLabel];
        //关注按钮
        _attendBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_attendBtn setImage:[UIImage imageNamed:@"CompetitionAttentionNO"] forState:UIControlStateNormal];
        [_attendBtn setImage:[UIImage imageNamed:@"CompetitionAttentionYES"] forState:UIControlStateSelected];
        KWeakSelf(self);
        [_attendBtn addBlockForControlEvents:UIControlEventTouchUpInside block:^(id  _Nonnull sender) {
            if (weakself.block) {
                weakself.block(sender);
            }
        }];
        _attendBtn.right = self.width - 30;
        _attendBtn.top = 0;
        _attendBtn.size = CGSizeMake(30, 30);
        [self addSubview:_attendBtn];
        
        //滚球
        _runBallImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"HomeGrounderBall"]];
        _runBallImageView.hidden = YES;
        _runBallImageView.right = _attendBtn.origin.x - 10;
        _runBallImageView.centerY = self.height/2;
        _runBallImageView.size = CGSizeMake(15, 15);
        [self addSubview:_runBallImageView];
        
    }
    return self;
}
@end;

#pragma mark -- LSCompetitiomSubBottomView
@implementation LSCompetitiomSubBottomView
- (instancetype)initWithFrame:(CGRect)frame{
    if (frame.size.width == 0 && frame.size.height == 0) {
        frame.size.width = LSScreenWidth;
        frame.size.height = 30;
    }
    if (self = [super initWithFrame:frame]) {
        //半球
        _banLabel = [YYLabel new];
        _banLabel.displaysAsynchronously = YES;
        _banLabel.ignoreCommonProperties = YES;
        _banLabel.fadeOnHighlight = NO;
        _banLabel.fadeOnAsynchronouslyDisplay = NO;
        _banLabel.right = self.width/2 - 50;
        //        _banLabel.centerY = self.height/2;
        _banLabel.size = CGSizeMake(40, 30);
        [self addSubview:_banLabel];
        //主队红牌
        _homeRedLabel = [YYLabel new];
        _homeRedLabel.displaysAsynchronously = YES;
        _homeRedLabel.ignoreCommonProperties = YES;
        _homeRedLabel.fadeOnHighlight = NO;
        _homeRedLabel.fadeOnAsynchronouslyDisplay = NO;
        _homeRedLabel.right = _banLabel.origin.x-3-_banLabel.size.width;
        //        _homeRedLabel.centerY = self.height/2;
        _homeRedLabel.size = CGSizeMake(30, 30);
        [self addSubview:_homeRedLabel];
        //主队黄牌
        _homeYellowLabel = [YYLabel new];
        _homeYellowLabel.displaysAsynchronously = YES;
        _homeYellowLabel.ignoreCommonProperties = YES;
        _homeYellowLabel.fadeOnHighlight = NO;
        _homeYellowLabel.fadeOnAsynchronouslyDisplay = NO;
        _homeYellowLabel.right = _homeRedLabel.origin.x-3-_homeRedLabel.size.width;
        //        _homeYellowLabel.centerY = self.height/2;
        _homeYellowLabel.size = CGSizeMake(30, 30);
        [self addSubview:_homeYellowLabel];
        //角球
        _jiaoLabel = [YYLabel new];
        _jiaoLabel.displaysAsynchronously = YES;
        _jiaoLabel.ignoreCommonProperties = YES;
        _jiaoLabel.fadeOnHighlight = NO;
        _jiaoLabel.fadeOnAsynchronouslyDisplay = NO;
        _jiaoLabel.left = self.width/2 + 10;
        _jiaoLabel.centerY = self.height/2;
        _jiaoLabel.size = CGSizeMake(40, 30);
        [self addSubview:_jiaoLabel];
        //客队红牌
        _guestRedLabel = [YYLabel new];
        _guestRedLabel.displaysAsynchronously = YES;
        _guestRedLabel.ignoreCommonProperties = YES;
        _guestRedLabel.fadeOnHighlight = NO;
        _guestRedLabel.fadeOnAsynchronouslyDisplay = NO;
        _guestRedLabel.left = _jiaoLabel.right + 3;
        _guestRedLabel.centerY = self.height/2;
        _guestRedLabel.size = CGSizeMake(30, 30);
        [self addSubview:_guestRedLabel];
        //客队黄牌
        _guestYellowLabel = [YYLabel new];
        _guestYellowLabel.displaysAsynchronously = YES;
        _guestYellowLabel.ignoreCommonProperties = YES;
        _guestYellowLabel.fadeOnHighlight = NO;
        _guestYellowLabel.fadeOnAsynchronouslyDisplay = NO;
        _guestYellowLabel.left = _guestRedLabel.right + 3;
        _guestYellowLabel.centerY = self.height/2;
        _guestYellowLabel.size = CGSizeMake(30, 30);
        [self addSubview:_banLabel];
        
        //底部的view
        CALayer * line = [CALayer layer];
        line.size = CGSizeMake(self.width, CGFloatToPixel(0.5));
        line.bottom = self.height;
        line.backgroundColor = LSLineGrayColor.CGColor;
        [self.layer addSublayer:line];
        
    }
    return self;
}
@end


#pragma mark ---- LSMatchScheduleCell
@interface LSMatchScheduleCell()
@property(strong,nonatomic)UILabel *cupTypeLab;

@property(strong,nonatomic)UILabel *timerLab;
@property(strong,nonatomic)UILabel *fisihMarkLab;

@property(strong,nonatomic)UILabel *hostNumLab;

@property(strong,nonatomic)UILabel *guestNumLab;

@property(strong,nonatomic)UILabel *hostNameLab;

@property(strong,nonatomic)UILabel *guestNameLab;
@property(strong,nonatomic)UIImageView *ballTypeImg;
@property(strong,nonatomic)UIImageView *TVImg;

@end
@implementation LSMatchScheduleCell

+ (LSMatchScheduleCell *)MatchScheduleTableviewCellByTableView:(UITableView *)tableView{
    
    LSMatchScheduleCell *cell=[tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self)];
    if (!cell) {
        cell = [[LSMatchScheduleCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self)];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
    
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addContentView];
    }
    
    return self;
}
- (void)addContentView{
    UIView *verView=[[UIView alloc]init];
    verView.backgroundColor=LSBackGroundColor;
    [self.contentView addSubview:verView];
    
    verView.sd_layout
    .leftEqualToView(self.contentView)
    .topEqualToView(self.contentView)
    .rightEqualToView(self.contentView)
    .heightIs(1.f);
    
    UILabel *cupTypeLab = [[UILabel alloc]init];
    cupTypeLab.font = LSFontSize11;
    cupTypeLab.textColor = LSTitleWhiteColor;
    cupTypeLab.backgroundColor = LSNavMainColor;
    cupTypeLab.layer.cornerRadius = 2;
    cupTypeLab.layer.masksToBounds = YES;
    cupTypeLab.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:cupTypeLab];
    self.cupTypeLab = cupTypeLab;
    cupTypeLab.sd_layout
    .leftEqualToView(self.contentView).offset(LSSpaceLeftWidth2)
    .topEqualToView(self.contentView).offset(10)
    .heightIs(20)
    .autoWidthRatio(2.5);
    
    UILabel *timerLab = [[UILabel alloc]init];
    timerLab.font = LSFontSize11;
    timerLab.textColor = LSTitleGrayColor2;
    timerLab.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:timerLab];
    self.timerLab = timerLab;
    timerLab.sd_layout
    .leftSpaceToView(cupTypeLab, 7)
    .topEqualToView(cupTypeLab)
    .heightIs(20)
    .autoWidthRatio(2.5);
    
    UILabel *fisihMarkLab = [[UILabel alloc]init];
    fisihMarkLab.font = LSFontSize12;
    fisihMarkLab.textColor = LSTitleGrayColor3;
    fisihMarkLab.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:fisihMarkLab];
    self.fisihMarkLab = fisihMarkLab;
    fisihMarkLab.sd_layout
    .leftEqualToView(cupTypeLab)
    .topSpaceToView(cupTypeLab, 20)
    .autoHeightRatio(0);
    [fisihMarkLab setSingleLineAutoResizeWithMaxWidth:180];
    
    
    UIView *lineView = [[UIView alloc]init];
    lineView.backgroundColor = LSLineGrayColor;
    [self.contentView addSubview:lineView];
    lineView.sd_layout
    .leftSpaceToView(fisihMarkLab,9)
    .topSpaceToView(cupTypeLab, 12)
    .widthIs(1.f)
    .bottomEqualToView(self.contentView).offset(-10);
    
    UILabel *vsLab = [[UILabel alloc] init];
    vsLab.text = @"VS";
    vsLab.textColor = RGB(180, 180, 180);
    vsLab.font = LSFontSize12;
    [self.contentView addSubview:vsLab];
    vsLab.sd_layout
    .centerYEqualToView(fisihMarkLab)
    .centerXEqualToView(self.contentView)
    .autoHeightRatio(0);
    [vsLab setSingleLineAutoResizeWithMaxWidth:180];
    
    UILabel *guestNameLab = [[UILabel alloc]init];
    guestNameLab.font = LSFontSize(14, LSScreenWidth);
    guestNameLab.numberOfLines = 2;
    guestNameLab.textColor = RGB(32,32,32);
    guestNameLab.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:guestNameLab];
    self.guestNameLab = guestNameLab;
    guestNameLab.sd_layout
    .leftSpaceToView(vsLab, 5)
    .centerYEqualToView(vsLab)
    .widthIs(LSAutoVlaue(67, LSScreenWidth))
    .autoHeightRatio(0);
    
    UILabel *guestNumLab = [[UILabel alloc]init];
    guestNumLab.font = LSFontSize9;
    guestNumLab.textColor = RGB(93,93,93);
    [self.contentView addSubview:guestNumLab];
    self.guestNumLab = guestNumLab;
    guestNumLab.sd_layout
    .leftSpaceToView(guestNameLab, 5)
    .centerYEqualToView(guestNameLab)
    .autoHeightRatio(0);
    [guestNumLab setSingleLineAutoResizeWithMaxWidth:180];
    
    UILabel *hostNameLab = [[UILabel alloc]init];
    hostNameLab.font = LSFontSize(14, LSScreenWidth);
    hostNameLab.numberOfLines = 2;
    hostNameLab.textColor = RGB(32,32,32);
    hostNameLab.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:hostNameLab];
    self.hostNameLab = hostNameLab;
    hostNameLab.sd_layout
    .rightSpaceToView(vsLab, 5)
    .centerYEqualToView(vsLab)
    .autoHeightRatio(0)
    .widthIs(LSAutoVlaue(67, LSScreenWidth));
    
    UILabel *hostNumLab = [[UILabel alloc]init];
    hostNumLab.font = LSFontSize9;
    hostNumLab.textColor = RGB(93,93,93);
    [self.contentView addSubview:hostNumLab];
    self.hostNumLab = hostNumLab;
    hostNumLab.sd_layout
    .rightSpaceToView(hostNameLab, 5)
    .centerYEqualToView(hostNameLab)
    .autoHeightRatio(0);
    [hostNumLab setSingleLineAutoResizeWithMaxWidth:180];
    
    
    
    
    //    UIImageView *ballTypeImg=[[UIImageView alloc]init];
    //    ballTypeImg.image=[UIImage imageNamed:@"HomeGrounderBall"];
    //    [self.contentView addSubview:ballTypeImg];
    //    self.ballTypeImg = ballTypeImg;
    //    ballTypeImg.sd_layout
    //    .rightSpaceToView(self.contentView, 10)
    //    .centerYEqualToView(vsLab)
    //    .widthIs(17)
    //    .heightEqualToWidth();
    
    //    UIImageView * TVImg = [[UIImageView alloc] init];
    //    TVImg.image = [UIImage imageNamed:@"Analyze"];
    //    [self.contentView addSubview:TVImg];
    //    self.TVImg = TVImg;
    //    TVImg.sd_layout
    //    .rightSpaceToView(ballTypeImg, 10)
    //    .centerYEqualToView(ballTypeImg)
    //    .widthIs(14)
    //    .heightEqualToWidth();
    
}

- (NSString *)getTimeStrWithStr:(NSString *)timeStr{
    
    NSString * timeStr1 = [timeStr componentsSeparatedByString:@"T"].lastObject;
    NSArray * array1 = [timeStr1 componentsSeparatedByString:@":"];
    NSMutableArray * array2 = [NSMutableArray arrayWithArray:array1];
    [array2 removeLastObject];
    NSString * str = [array2 componentsJoinedByString:@":"];
    return str;
}
- (void)setModel:(LSMatchScheduleModel *)model{
    _model = model;
    self.cupTypeLab.text = model.LeagueName;
    self.cupTypeLab.backgroundColor = [CommonClass colorWithHexString:model.LeagueCorol];
    self.hostNameLab.text = model.MasterTeamName;
    self.hostNumLab.text = model.MasterTeamOrder;
    self.guestNameLab.text = model.GuestTeamName;
    self.guestNumLab.text = model.GuestTeamOrder;
    self.fisihMarkLab.text = @"未";
    self.timerLab.text = [self getTimeStrWithStr:model.MatchTime];
    switch (model.MatchDate) {
        case -1:{
            //结束
            self.fisihMarkLab.text = @"完";
            
            
            self.timerLab.text = [self getTimeStrWithStr:model.MatchTime];
        }
            break;
        case 0:{
            //未开始
            self.fisihMarkLab.text = @"未";
            self.timerLab.text = [self getTimeStrWithStr:model.MatchTime];
        }
            break;
            
        case 1:{
            //上半场
            self.fisihMarkLab.text = @"55'";
            self.timerLab.text = [self getTimeStrWithStr:model.MatchTime];
        }
            break;
        case 3:{
            //下半场
            self.fisihMarkLab.text = @"55'";
            self.timerLab.text = [self getTimeStrWithStr:model.MatchTime];
        }
            break;
        default:
            break;
    }
}

@end

